package com.example.prototype;

import com.example.prototype.shape.Shape;
import com.example.prototype.shape.impl.Circle;
import com.example.prototype.shape.impl.Rectangle;
import com.example.prototype.shape.impl.Square;
import java.util.HashMap;

/**
 * @Description TODO
 * @Date 2021/10/28 16:06
 * @Author ZhangJi
 * @Version 1.0
 */
public class ShapeCache {

  private static HashMap<String, Shape> shapeHashMap= new HashMap<String, Shape>();

  public static void loadCache(){
    Circle circle = new Circle();
    circle.setId("1");
    shapeHashMap.put(circle.getId(),circle);

    Square square = new Square();
    square.setId("2");
    shapeHashMap.put(square.getId(),square);

    Rectangle rectangle = new Rectangle();
    rectangle.setId("3");
    shapeHashMap.put(rectangle.getId(),rectangle);
  }

  public static Shape getShape(String shapeID){
    return (Shape) shapeHashMap.get(shapeID).clone();
  }

}
